home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_dos.lha / dos / sphsrc.v08 / sph_element.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-26  |  5.5 KB  |  347 lines

  1. #include "HEADERS.h"
  2. #include "sphigslocal.h"
  3. #include <string.h>
  4.  
  5.  
  6. element *baby;
  7.  
  8. #define MAKE_BABY_ELEMENT   baby = (element*) malloc ((size_t)sizeof(element))
  9. #define INSERT_BABY        SPH__insertElement (baby)
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. /*!*/
  18. static
  19. char *MAKE_COPY_OF_STRING (char *str)
  20. {
  21.    char *copy;
  22.  
  23.    copy = (char*) malloc (strlen(str)+1);
  24.    strcpy(copy,str);
  25.    return copy;
  26. }
  27.  
  28.  
  29.  
  30.  
  31. /*!*/
  32. void
  33. SPH_setModelingTransformation (matrix mat, int method)
  34. {
  35.    SPH_check_system_state;
  36.    SPH_check_open_structure;
  37.    SPH_check_modxform_method;
  38.  
  39.    MAKE_BABY_ELEMENT;
  40.    baby->type = ELTYP__SET_MODXFORM;
  41.    baby->info.update_type = method;
  42.    MAT3copy (baby->data.matrix, mat);
  43.    INSERT_BABY;
  44. }
  45.  
  46.  
  47. /*!*/
  48. void
  49. SPH_clearModelingTransformation (void)
  50. {
  51.    SPH_check_system_state;
  52.    SPH_check_open_structure;
  53.  
  54.    MAKE_BABY_ELEMENT;
  55.    baby->type = ELTYP__CLEAR_MODXFORM;
  56.    INSERT_BABY;
  57. }
  58.  
  59.  
  60.  
  61.  
  62. /*!*/
  63. /* not called directly by the application, called by SPH_polyhedron */
  64. void
  65. SPH__add_polyhedron_element (POLYHEDRON *newpoly)
  66. {
  67.    register i;
  68.  
  69.    MAKE_BABY_ELEMENT;
  70.    baby->type = ELTYP__POLYHEDRON;
  71.    baby->data.poly = newpoly;
  72.  
  73.    INSERT_BABY;
  74. }
  75.  
  76.  
  77.  
  78.  
  79. /*!*/
  80. void
  81. SPH_text (origin, string)
  82. point origin;
  83. char *string;
  84. {
  85.    SPH_check_system_state;
  86.    SPH_check_open_structure;
  87.  
  88.    MAKE_BABY_ELEMENT;
  89.    baby->type = ELTYP__TEXT;
  90.    baby->info.textstring = MAKE_COPY_OF_STRING (string);
  91.    bcopy (origin, baby->data.point, sizeof(point));
  92.    baby->data.point[3] = 1.0;   /* h-coordinate */
  93.    INSERT_BABY;
  94. }
  95.  
  96.  
  97.  
  98. static void
  99. StorePointList (element *baby, int vCount, point *verts)
  100. {
  101.    register i;
  102.  
  103.    baby->info.count = vCount;
  104.    ALLOC (baby->data.points, MAT3hvec, vCount, 0);
  105.  
  106.    /* COPY VERTICES, TRANSFORMING TO HVERTS. */
  107.    for (i=0; i<vCount; i++)
  108.       MAT3_SET_HVEC (baby->data.points[i] ,
  109.              verts[i][0], verts[i][1], verts[i][2], 1.0);
  110. }
  111.  
  112.  
  113.  
  114. /*!*/
  115. void
  116. SPH_polyLine (int vCount, point *verts)
  117. {
  118.    SPH_check_system_state;
  119.    SPH_check_open_structure;
  120.  
  121.    MAKE_BABY_ELEMENT;
  122.    baby->type = ELTYP__POLYLINE;
  123.    StorePointList (baby, vCount, verts);
  124.    INSERT_BABY;
  125. }
  126.  
  127.  
  128.  
  129. /*!*/
  130. void
  131. SPH_polyMarker (int vCount, point *verts)
  132. {
  133.    SPH_check_system_state;
  134.    SPH_check_open_structure;
  135.  
  136.    MAKE_BABY_ELEMENT;
  137.    baby->type = ELTYP__POLYMARKER;
  138.    StorePointList (baby, vCount, verts);
  139.    INSERT_BABY;
  140. }
  141.  
  142.  
  143.  
  144. /*!*/
  145. void
  146. SPH_fillArea (int vCount, point *verts)
  147. {
  148.    SPH_check_system_state;
  149.    SPH_check_open_structure;
  150.  
  151.    MAKE_BABY_ELEMENT;
  152.    baby->type = ELTYP__FILL_AREA;
  153.    StorePointList (baby, vCount, verts);
  154.    INSERT_BABY;
  155. }
  156.  
  157.  
  158.  
  159.  
  160. static void SimpleElement (int type, int value)
  161. {
  162.    SPH_check_system_state;
  163.    SPH_check_open_structure;
  164.  
  165.    MAKE_BABY_ELEMENT;
  166.    baby->type = type;
  167.    baby->data.value = value;
  168.    INSERT_BABY;
  169. }
  170.  
  171.  
  172. /*!*/
  173. void
  174. SPH_label (lab)
  175. int lab;
  176. {
  177.    SimpleElement (ELTYP__LABEL,lab);
  178. }
  179.  
  180.  
  181. /*!*/
  182. void
  183. SPH_setPickIdentifier (lab)
  184. int lab;
  185. {
  186.    SimpleElement (ELTYP__PICK_ID,lab);
  187. }
  188.  
  189.  
  190. /*!*/
  191. void
  192. SPH_setInteriorColor (value)
  193. int value;
  194. {
  195.    if ( ! IS_LEGAL_COLOR_INDEX(value))
  196.       value = 0;  /* white is default color index for interiors */
  197.    SimpleElement (ELTYP__SET_INTERIOR_COLOR,value);
  198. }
  199.  
  200. /*!*/
  201. void
  202. SPH_setLineColor (value)
  203. int value;
  204. {
  205.    if ( ! IS_LEGAL_COLOR_INDEX(value))
  206.       value = 1;  /* black is default color index for framed objects */
  207.    SimpleElement (ELTYP__SET_LINE_COLOR,value);
  208. }
  209.  
  210. /*!*/
  211. void
  212. SPH_setLineWidthScaleFactor (double value)
  213. {
  214.    register i;
  215.    
  216.    SimpleElement 
  217.       (ELTYP__SET_LINE_WIDTH,
  218.        ((i=LINE_WIDTH_UNIT_IN_PIXELS*value) < 1) ? 1 : i);
  219. }
  220.  
  221. /*!*/
  222. void
  223. SPH_setLineStyle (value)
  224. int value;
  225. {
  226.    SimpleElement (ELTYP__SET_LINE_STYLE,value);
  227. }
  228.  
  229. /*!*/
  230. void
  231. SPH_setMarkerColor (value)
  232. int value;
  233. {
  234.    if ( ! IS_LEGAL_COLOR_INDEX(value))
  235.       value = 1;  /* black is default color index for framed objects */
  236.    SimpleElement (ELTYP__SET_MARKER_COLOR,value);
  237. }
  238.  
  239. /*!*/
  240. void
  241. SPH_setMarkerSizeScaleFactor (double value)
  242. {
  243.    register i;
  244.    
  245.    SimpleElement 
  246.       (ELTYP__SET_MARKER_SIZE,
  247.        ((i=MARKER_SIZE_UNIT_IN_PIXELS*value) < 1) ? 1 : i);
  248. }
  249.  
  250. /*!*/
  251. void
  252. SPH_setMarkerStyle (value)
  253. int value;
  254. {
  255.    SimpleElement (ELTYP__SET_MARKER_STYLE,value);
  256. }
  257.  
  258. /*!*/
  259. void
  260. SPH_setEdgeColor (value)
  261. int value;
  262. {
  263.    if ( ! IS_LEGAL_COLOR_INDEX(value))
  264.       value = 1;  /* black is default color index for framed objects */
  265.    SimpleElement (ELTYP__SET_EDGE_COLOR,value);
  266. }
  267.  
  268. /*!*/
  269. void
  270. SPH_setEdgeStyle (value)
  271. int value;
  272. {
  273.    SimpleElement (ELTYP__SET_EDGE_STYLE,value);
  274. }
  275.  
  276. /*!*/
  277. void
  278. SPH_setEdgeFlag (value)
  279. int value;
  280. {
  281.    SimpleElement (ELTYP__SET_EDGE_FLAG,value);
  282. }
  283.  
  284. /*!*/
  285. void
  286. SPH_setEdgeWidthScaleFactor (double value)
  287. {
  288.    register i;
  289.    
  290.    SimpleElement 
  291.       (ELTYP__SET_EDGE_WIDTH,
  292.        ((i=LINE_WIDTH_UNIT_IN_PIXELS*value) < 1) ? 1 : i);
  293. }
  294.  
  295.  
  296.  
  297.  
  298. /*!*/
  299. void
  300. SPH_setTextFont (value)
  301. int value;
  302. {
  303.    SimpleElement (ELTYP__SET_TEXT_FONT, value);
  304. }
  305.  
  306. /*!*/
  307. void
  308. SPH_setTextColor (value)
  309. int value;
  310. {
  311.    if ( ! IS_LEGAL_COLOR_INDEX(value))
  312.       value = 1;  /* black is default color index for framed objects */
  313.    SimpleElement (ELTYP__SET_TEXT_COLOR, value);
  314. }
  315.  
  316.  
  317.  
  318.  
  319.  
  320. /** Borrows data from edit.c **/
  321. extern structure *OPENSTRUCT;
  322. extern int ID_of_open_struct;
  323.  
  324. void
  325. SPH_executeStructure (int structID)
  326. {
  327.    register int sid;
  328.  
  329.  
  330.    SPH_check_system_state;
  331.    SPH_check_open_structure;
  332.    SPH_check_structure_id;
  333.  
  334.    MAKE_BABY_ELEMENT;
  335.    baby->type = ELTYP__EXECUTE_STRUCTURE;
  336.    baby->data.value = structID;
  337.    INSERT_BABY;
  338.  
  339.    SPH__structureTable[structID].refcount++;
  340.  
  341.    /* UPDATE THE OPEN STRUCTURE'S CHILD_LIST. */
  342.    SetBit (OPENSTRUCT->child_list, structID);
  343.  
  344.    /* UPDATE VIEWS' DESCENDENT LISTS! */
  345.    VIEWOPT__newExecuteStructure (ID_of_open_struct, structID);
  346. }
  347.